/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view.panels.graphical.drawables;

import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Polygon;
import java.awt.geom.Point2D;
import jgf.beans.ArcBean;

/**
 *
 * @author Marcos Garcia Ortega <a href="mailto:thiamath@gmail.com">&lt;thiamath@gmail.com&gt;</a>
 */
public class DrawDiarc extends DrawArc {

	//protected QuadCurve2D.Float shape;
	protected Polygon arrow;

	public DrawDiarc(ArcBean arc) {
		super(arc);
		arrow = new Polygon();
	//shape = new QuadCurve2D.Float();
	// TODO encontrar la forma de rehacer los arcos para que se ajusten a la nueva forma
	// No funcionaran ni setOrigin ni setEnd y probablemente muchos otros tampoco.
	}

	DrawDiarc(Point x, Point y) {
		super(x, y);
		arrow = new Polygon();
	}

	@Override
	public void display(Graphics2D g) {
		super.display(g);
		this.drawArrow(g, shape.getP2(), shape.getP1());
	}

	protected static double ARROW_ANGLE = Math.PI / 4;
	protected static int ARROW_LENGTH = 15;

	private void drawArrow(Graphics2D g, Point2D head, Point2D away) {
		int endX, endY;
		double angle = Math.atan2((double) (away.getX() - head.getX()),
				(double) (away.getY() - head.getY()));
		angle += ARROW_ANGLE;
		arrow.addPoint((int) head.getX(), (int) head.getY());
		endX = (int) (((Math.sin(angle) * ARROW_LENGTH)) + head.getX());
		endY = (int) (((Math.cos(angle) * ARROW_LENGTH)) + head.getY());
		//g.drawLine((int)head.getX(), (int)head.getY(), endX, endY);
		arrow.addPoint(endX, endY);
		angle -= 2 * ARROW_ANGLE;
		endX = (int) (((Math.sin(angle) * ARROW_LENGTH)) + head.getX());
		endY = (int) (((Math.cos(angle) * ARROW_LENGTH)) + head.getY());
		//g.drawLine((int)head.getX(), (int)head.getY(), endX, endY);
		arrow.addPoint(endX, endY);
		angle += ARROW_ANGLE;
		if (this.from != -1 || this.to != -1) {
			endX = (int) (Math.sin(angle) * DrawNode.RADIUS);
			endY = (int) (Math.cos(angle) * DrawNode.RADIUS);
			arrow.translate(endX, endY);
		}
		g.fill(arrow);
		arrow.reset();
	}

}
